package simplemr;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class WordCountMap extends Mapper<LongWritable,Text, Text, IntWritable> {

    /**
     * 处理分片split中的每一行数据，针对每行数据，会调用一次map
     * 在map调用时，从一行数据中，获得一个个单词word，再将每个单词变成键值对形式(word,1)输出出去
     * @param key 当前所读行行首相对于split分片开头的字节偏移量
     * @param value 当前所读行
     *
     * **/
     public void map(LongWritable key,Text value,Context context) throws IOException,InterruptedException {
         //取得当前行数据
         String line = value.toString();
         String[] words = line.split("\t");

         for(String word : words){
             context.write(new Text(word),new IntWritable(1));
         }
      }
}
